NUMERICAL MATHEMATICS

x=123.123456789123456789

Precision[x]

?Precision

Accuracy[x]

?Accuracy

N[x,9]

y=N[Pi,25]

Accuracy[y]

Precision[y]

Precision[1]

Precision[1.]

?$MachinePrecision

$MachinePrecision

Exp[N[2 Pi I]]

Chop[%]

0/0

1/0

Abs[%]

1/%

Rationalize[45.78]

x=452.45834

Rationalize[x]

Rationalize[x,10^-3]

Rationalize[x,0]

Round[x]

Round[x+.5]

FactorInteger[Round[x]]

RandomReal[]

RandomInteger[{1,100}]

RandomInteger[100]

GCD[10,20,45]

LCM[10,25,36]

Log[E]

Log[2]

Log[2,2]

Sqrt[3]

Sqrt[3]//N

Prime[10]

PrimeQ[Prime[10]]

Table[Prime[i], {i,1,10}]

x=3+5I; y=5+7I;

x+y

Head[%]

(a+8I)+(4 I+b)

(a+8I)*(4 I+b)

(a+8I)*(4 I+b)//Expand

Re[%]

Σταθερές Ε,Ι,Pi

Pi

I

E

Αριθμητική εύρεση ριζών

Clear["`*"]

g[x]:=x^7-x^3+17 x+10==0

rts=NSolve[g[x],x]

x/.rts

g[x]

g[x][[1]]

Plot[10+17 x-(x^3)+(x^7),{x,-10,10}]

f[x_]:=1+x^2 Sin[x]-Tan[Log[x^2+1]]

NSolve[f[x]==0,x];

Table[FindRoot[f[x]==0,{x,i}], {i,50,60,0.5}]

searchforroots[a_,b_,d_]:=Module[{r},r=Table[If[i!=0,FindRoot[f[x]==0,{x,i}]], {i,a,b,d}];r]

rts=searchforroots[50,60,0.5]

rtpoints=x/.rts

rtpoints=Union[rtpoints]

(f[x]/.rts)//Chop

r1=FindRoot[f[x]==0,{x,0}]

r1

f[x]/.r1

f[x]

Plot[f[x],{x,-3,3}]

FindRoot[f[x],{x,1.5},StepMonitor:>Print["Step to x = ",x]]

Plot[Sqrt[Abs[x-1]],{x,-2,3}]

FindRoot[Sqrt[Abs[x-1]]==0,{x,0,3},AccuracyGoal->6,MaxIterations->100]

s=0;
sol=FindRoot[Sqrt[Abs[x-1]]==0,{x,0,3},AccuracyGoal->6,DampingFactor->1,MaxIterations->100,StepMonitor:>s++]
s

x=.

sol=FindRoot[Sqrt[Abs[x-1]]==0,{x,0,3},AccuracyGoal->6,MaxIterations->100]

x1=x/.sol

x1

Sqrt[Abs[x-1]]/.sol

funcs={y^x-x,y^x Log[y]-1}

eqfuncs={y^x-x,x^y-y}

Plot3D[eqfuncs,{x,0,5},{y,0,5}]

ContourPlot[eqfuncs,{x,0,5},{y,0,5}]

FindRoot[funcs,{x,0.3},{y,0.2}]

(funcs/.%) //Chop

Άλλοι αριθμητικοί υπολογισμοί

FindMinimum[Sin[x^2+y^2],{x,1},{y,1}]

N[Sqrt[3 Pi/4]]

x

g[x]

Part[g[x],1]

g[x][[1]]/. {{x->1}}

g[x][[1]]/. {x->1,x->2}

a+b+c/. {{a->1},{b->2}}

sol=Solve[(x-2)*(x-3)*(x+5)==0]

x/.sol

Table[RandomInteger[10],{i,1,5}]

m=Table[RandomInteger[5],{i,1,5},{j,1,5}]

Det[m]

m//MatrixForm

Head[m]

FullForm[m]

m+m//MatrixForm

m*m//MatrixForm

m.m//MatrixForm

Transpose[m]//MatrixForm

Det[m]

Inverse[m]

m.%

m=Table[RandomInteger[5],{i,1,3},{j,1,3}]

Det[m]

cpm=CharacteristicPolynomial[m,x]

NSolve[cpm==0,x]

Eigenvalues[m]

Eigenvalues[m]//N

Eigenvectors[m]

Αριθμητική Ολοκλήρωση, Άθροιση

NIntegrate[Sin[x]/x,{x,0,1}]

NIntegrate[(Sin[x]-x Cos[x])/Sin[x]^2,{x,Pi/6, Pi/2}]

Pi/6 //N

Integrate[(Sin[x]-x Cos[x])/Sin[x]^2,x]

Sum[i,{i,1,100}]

Sum[i,{i,1,n}]

Sum[(x+a)^i,{i,1,10}]

%//Expand

Product[(x-i),{i,1,5}]

%//Expand

Διαφορικές Εξισώσσεις

de1=y'[x]== x^2 y[x]

sol=NDSolve[de1,y,{x,0,2}]

sol[[1,1,2]]

sol[[1,1]]

y[x]/.sol

y[0.09523]/.sol

de1=y'''[x]+ Log[x]  y''[x]+2y[x]==x^2;
sol=NDSolve[{de1, y''[1]==0,y'[1]==0,y[1]==0},y,{x,1,4}];
Plot[y[x]/. sol, {x,1,4}]

Plot[y[x]/. sol, {x,1,2}]

Plot[Evaluate[y[x]/. sol], {x,0,2}]

de1=2 y[x]+y''[x]+Derivative[3
][y][x]==(x^2)

y''[1]==0,y'[1]==0,y[1]==0

de1=2 y[x]+3y'[x]-y''[x]==-x;
sol=DSolve[de1,y[x],x];
sol=sol[[1]];Print[sol];
fun=(y[x]/.sol);
ex1=(fun/.x->1)==0;
ex2=(D[fun,x]/.x->1)==0;
ics=Solve[{ex1,ex2},{C[1],C[2]}]//N;
ics=ics[[1]];
sol=(sol/.ics)[[1,2]];sol=sol//N;
Print[sol];
Plot[sol,{x,-3,3}]

fun=sol[[1,1,2]]

fun=(y[x]/.sol)[[1]]

ex1=(fun/.x->1)==0

ex2=(D[fun,x]/.x->1)==0

Solve[{ex1,ex2},{C[1],C[2]}]//N

funwic=(fun /.Solve[(fun /.x->0)==1,C[1]])[[1]]

Plot[funwic,{x,0,2}]